package com.rcdz.mykotlindemo.designtest

import android.view.MenuItem
import android.view.View
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.rcdz.mykotlindemo.R
import com.rcdz.mykotlindemo.view.fragment.FristFragment
import com.rcdz.mykotlindemo.view.fragment.TwoFragment
import com.wjt.mylibrary.base.BaseFragment


/**
 * tab+viewPager
 */
class TabFragment : BaseFragment() {
    var mNavigationView: BottomNavigationView? = null
    private var fragments: List<Fragment>? = null
    override fun lazyInit() {
    }

    override fun setNowActivityName(): String {
      return "TabFragment"
    }

    override fun setLayout(): Int {
       return R.layout.fragment_tab
    }

    override fun initView() {
        mNavigationView = getRootView().findViewById(R.id.bottom_nav)
        fragments = ArrayList<Fragment>()
        (fragments as ArrayList<Fragment>).add(FristFragment())
        (fragments as ArrayList<Fragment>).add(TwoFragment())
        (fragments as ArrayList<Fragment>).add(TwoFragment())
        val index = 0
        switchFragment(index)


    }

    private fun switchFragment(index: Int) {
        activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.fragment_container, fragments!![index])?.commit()
    }

    override fun initData() {
        mNavigationView?.setOnNavigationItemSelectedListener(BottomNavigationView.OnNavigationItemSelectedListener { menuItem: MenuItem ->
            when (menuItem.itemId) {
                R.id.tab_home -> switchFragment(0)
                R.id.tab_template -> switchFragment(1)
                R.id.tab_mine -> switchFragment(2)
            }
            true
        })
    }

    override fun onClick(v: View?) {
    }

}
